package com.ruoyi.web.controller.sports;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sports.domain.SportsMeeting;
import com.ruoyi.sports.service.ISportsMeetingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运动会Controller
 * 
 * @author ZJH
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/sports/sportsmeeting")
public class SportsMeetingController extends BaseController
{
    @Autowired
    private ISportsMeetingService sportsMeetingService;

    /**
     * 查询运动会列表
     */
    @PreAuthorize("@ss.hasPermi('sports:sportsmeeting:list')")
    @GetMapping("/list")
    public TableDataInfo list(SportsMeeting sportsMeeting)
    {
        startPage();
        List<SportsMeeting> list = sportsMeetingService.selectSportsMeetingList(sportsMeeting);
        return getDataTable(list);
    }

    /**
     * 导出运动会列表
     */
    @PreAuthorize("@ss.hasPermi('sports:sportsmeeting:export')")
    @Log(title = "运动会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SportsMeeting sportsMeeting)
    {
        List<SportsMeeting> list = sportsMeetingService.selectSportsMeetingList(sportsMeeting);
        ExcelUtil<SportsMeeting> util = new ExcelUtil<SportsMeeting>(SportsMeeting.class);
        util.exportExcel(response, list, "运动会数据");
    }

    /**
     * 获取运动会详细信息
     */
    @PreAuthorize("@ss.hasPermi('sports:sportsmeeting:query')")
    @GetMapping(value = "/{sportsMeetingId}")
    public AjaxResult getInfo(@PathVariable("sportsMeetingId") Long sportsMeetingId)
    {
        return success(sportsMeetingService.selectSportsMeetingBySportsMeetingId(sportsMeetingId));
    }

    /**
     * 新增运动会
     */
    @PreAuthorize("@ss.hasPermi('sports:sportsmeeting:add')")
    @Log(title = "运动会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SportsMeeting sportsMeeting)
    {
        return toAjax(sportsMeetingService.insertSportsMeeting(sportsMeeting));
    }

    /**
     * 修改运动会
     */
    @PreAuthorize("@ss.hasPermi('sports:sportsmeeting:edit')")
    @Log(title = "运动会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SportsMeeting sportsMeeting)
    {
        return toAjax(sportsMeetingService.updateSportsMeeting(sportsMeeting));
    }

    /**
     * 删除运动会
     */
    @PreAuthorize("@ss.hasPermi('sports:sportsmeeting:remove')")
    @Log(title = "运动会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sportsMeetingIds}")
    public AjaxResult remove(@PathVariable Long[] sportsMeetingIds)
    {
        return toAjax(sportsMeetingService.deleteSportsMeetingBySportsMeetingIds(sportsMeetingIds));
    }
}
